﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Exp {
	public partial class Edit1 : System.Web.UI.Page {
		protected void Page_Load(object sender, EventArgs e) {
			string rowid = Request.QueryString["rowid"];
			if (string.IsNullOrEmpty(rowid)) {
				return;
			}
			if (!Page.IsPostBack) {
				string SQL = @"
						SELECT 
							ROWID,
							LINE_NO,
							PRODUCT_DATE,
							START_TIME,
							SCHDL_NO,
							SEQ_NO,
							ORDER_ITEM_NO
						FROM EXAMPLE 
						WHERE ROWID = '" + rowid + "'";

				try {
					using (
						DataSet ds = SqlHelper.ExecuteDataset(
							System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString,
							CommandType.Text,
							SQL
						)
					) {
						if (ds == null || ds.Tables[0].Rows.Count == 0) {
							return;
						}
						DataRow row = ds.Tables[0].Rows[0];

						ROWID.Text = row["ROWID"].ToString();
						LINE_NO.Text = row["LINE_NO"].ToString();
						PRODUCT_DATE.Text = row["PRODUCT_DATE"].ToString();
						START_TIME.Text = row["START_TIME"].ToString();
						SCHDL_NO.Text = row["SCHDL_NO"].ToString();
						ORDER_ITEM_NO.Text = row["ORDER_ITEM_NO"].ToString();

					}
				}
				catch (System.Exception ex) {
					throw new Exception("查询失败", ex);
				}
			}
		}

		protected void Submit_Click(object sender, EventArgs e) {

			string rowid = ROWID.Text;
			string line_no = LINE_NO.Text;
			string product_date = PRODUCT_DATE.Text;
			string start_time = START_TIME.Text;
			string schdl_no = SCHDL_NO.Text;
			string order_item_no = ORDER_ITEM_NO.Text;



			string SetItem = "";
			SetItem += " LINE_NO = '" + line_no + "' ";

			DateTime dt;
			if (DateTime.TryParse(product_date, out dt)) {
				SetItem += " , PRODUCT_DATE = '" + dt.ToString() + "' ";
			}

			SetItem += " , START_TIME = '" + start_time + "'  ";
			SetItem += " , SCHDL_NO = " + schdl_no + " ";
			SetItem += " , ORDER_ITEM_NO = '" + order_item_no + "' ";

			string SQL = @"
						UPDATE EXAMPLE SET " + SetItem + @"WHERE ROWID = '" + rowid + "'";

			try {
				int ret = SqlHelper.ExecuteNonQuery(
					System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString,
					CommandType.Text,
					SQL
				);
				if(ret == 1){
					Message.Text = "修改成功！";
				}
			}
			catch (System.Exception ex) {
				throw new Exception("修改失败", ex);
			}
		}
	}
}